{layout name="public/layout" /}
{include file='yxnavbar'}


<div class="main">
    {include file='../../plugin/gift/template/web/common_nav'}

    <div class="panel panel-info">
        <div class="panel-heading">当前数量： {$page_total}</div>
        <div class="panel-body">
            <form id="myform" action="./index.php" method="get" class="form-horizontal" role="form">
                <input type="hidden" name="c" value="site" />
                <input type="hidden" name="a" value="entry" />
                <input type="hidden" name="m" value="{$_P['m']}" />
                <input type="hidden" name="do" value="web" />
                <input type="hidden" name="r" value="gift.record.gain" />
                <div class="form-group">
                    <label class="col-xs-1 col-sm-1 col-md-1 control-label">状态</label>
                    <div class="col-xs-11 col-sm-9 col-md-9">
                        <div class="btn-group">
                            {loop $status_list $row}
                            <a href="{php echo createWebUrlPlugin('gift.record.gain',array('themeid'=>$themeid,'status'=>$row['status']));}" class="btn {if !$classify&&$status == $row['status']}btn-primary{else}btn-default{/if}">
                                {$row['title']}
                                <span style="color: #ff0000">{$row['total']}</span>
                            </a>
                            {/loop}
                        </div>
                    </div>
                    {if count($themelist)>1 }
                        <div class="col-xs-12 col-sm-2 col-md-2">
                            <select onchange="submitForm();" class="form-control" name="themeid">
                                {loop $themelist $row}
                                <option value="{$row['id']}" {if $themeid == $row['id'] }selected="selected"{/if}>{$row['id']} - {php echo mb_substr($row['title'],0,8,'utf-8');}</option>
                                {/loop}
                            </select>
                        </div>
                    {else}
                        <input type="hidden" name="themeid" value="{$themeid}" />
                    {/if}
                </div>

                {if count($tuan_gift)>1}
                    <div class="form-group">
                        <label class="col-xs-1 col-sm-1 col-md-1 control-label">成团礼</label>
                        <div class="col-xs-11 col-sm-9 col-md-9">
                            {loop $tuan_gift $row}
                            <div class="btn-group">
                                <button class="btn btn-default">
                                    {$row['name']}
                                </button>
                                <a class="btn {if $classify=='tuan_gift' && $gift_id==$row['id'] && $status==1 } btn-primary {else} btn-default {/if}"  href="{php echo createWebUrlPlugin('gift.record.gain',array('themeid'=>$themeid,'classify'=>'tuan_gift','gift_id'=>$row['id'],'status'=>1));}">
                                    未核销 <span style="color: #ff0000">{$row['total']}</span>
                                </a>
                                <a class="btn {if $classify=='tuan_gift' && $gift_id==$row['id'] && $status==2 } btn-primary {else} btn-default {/if}"  href="{php echo createWebUrlPlugin('gift.record.gain',array('themeid'=>$themeid,'classify'=>'tuan_gift','gift_id'=>$row['id'],'status'=>2));}">
                                    已核销 <span style="color: #8ccdfb">{$row['exchange_total']}</span>
                                </a>
                            </div>
                            {/loop}
                        </div>
                    </div>
                {/if}

                {if count($invite_gift)>1}
                    <div class="form-group">
                        <label class="col-xs-1 col-sm-1 col-md-1 control-label">邀请下单</label>
                        <div class="col-xs-11 col-sm-9 col-md-9">
                            {loop $invite_gift $row}
                            <div class="btn-group">
                                <button class="btn btn-default">
                                    {$row['name']}
                                </button>
                                <a class="btn {if $classify=='invite_gift' && $gift_id==$row['id'] && $status==1 } btn-primary {else} btn-default {/if}"  href="{php echo createWebUrlPlugin('gift.record.gain',array('themeid'=>$themeid,'classify'=>'invite_gift','gift_id'=>$row['id'],'status'=>0));}">
                                    未核销 <span style="color: #ff0000"> {$row['total']}</span>
                                </a>
                                <a class="btn {if $classify=='invite_gift' && $gift_id==$row['id'] && $status==2 } btn-primary {else} btn-default {/if}"  href="{php echo createWebUrlPlugin('gift.record.gain',array('themeid'=>$themeid,'classify'=>'invite_gift','gift_id'=>$row['id'],'status'=>2));}">
                                    已核销 <span style="color: #8ccdfb"> {$row['exchange_total']}</span>
                                </a>
                            </div>
                            {/loop}
                        </div>
                    </div>
                {/if}
                {if count($help_gift)>1}
                <div class="form-group">
                    <label class="col-xs-1 col-sm-1 col-md-1 control-label">邀请助力</label>
                    <div class="col-xs-11 col-sm-9 col-md-9">
                        {loop $help_gift $row}
                        <div class="btn-group">
                            <button class="btn btn-default">
                                {$row['name']}
                            </button>
                            <a class="btn {if $classify=='invite_gift' && $gift_id==$row['id'] && $status==1 } btn-primary {else} btn-default {/if}"  href="{php echo createWebUrlPlugin('gift.fans',array('themeid'=>$themeid,'classify'=>'help_gift','gift_id'=>$row['id'],'status'=>1));}">
                                未核销 <span style="color: #ff0000"> {$row['total']}</span>
                            </a>
                            <a class="btn {if $classify=='invite_gift' && $gift_id==$row['id'] && $status==2 } btn-primary {else} btn-default {/if}"  href="{php echo createWebUrlPlugin('gift.fans',array('themeid'=>$themeid,'classify'=>'help_gift','gift_id'=>$row['id'],'status'=>2));}">
                                已核销 <span style="color: #8ccdfb"> {$row['exchange_total']}</span>
                            </a>
                        </div>
                        {/loop}
                    </div>
                </div>
                {/if}

                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-1 control-label">时间</label>
                    <div class="col-sm-3 col-lg-4 col-md-5 col-xs-6">
                        <select name="time_type" id="time_type">
                            <option value="1">创建时间</option>
                            <option value="2">核销时间</option>
                        </select>
                        {php echo view_form_field_daterange('createtime', array('start'=>$starttime,'end'=>$endtime),true);}
                    </div>
                </div>

                <div class="form-group clearfix">
                    <label class="col-xs-12 col-sm-3 col-md-1 control-label">关键字</label>
                    <div class="col-sm-4 col-xs-4 col-md-4">
                        <input class="form-control" name="search_data" placeholder="输入报名手机号、微信昵称、客资姓名" type="text" value="{$search_data}">
                    </div>
                    <div class="col-sm-3 col-lg-3 col-md-3 col-xs-6">
                        <button type="submit"  class="btn btn-primary"><i class="fa fa-search"></i>搜索</button>
                        <input type="hidden" name="__token__" value="{$Request.token}"/>
                    </div>
                    <div class="col-sm-2 col-lg-2 col-md-2 col-xs-2">
                        <input class="btn btn-default" type="submit" name="export_submit" onclick="jump()" id="export_submit" value="导出邀请礼获得奖品数据">
                    </div>
                    <div class="btn-group">
                        <a class="btn btn-success" onclick="validation()">礼品记录效验</a>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <div class="tab-content">
        <div class="panel panel-default">
            <div class="panel-body table-responsive">
                <table class="table table-hover">
                    <thead class="navbar-inner">
                    <tr>
                        <th style="width: 50px">序号</th>
                        <th style="width: 100px">昵称</th>
                        <th style="width: 100px">姓名/电话</th>
                        <th style="width: 100px">礼品名称</th>
                        <th style="width: 100px">礼品价值</th>
                        <th style="width: 100px">奖项类型</th>
                        <th style="width: 100px">获取条件</th>
                        <th style="width: 100px">员工信息</th>
                        <th style="width: 100px">核销状态</th>
                        <th style="width: 100px">领取时间</th>
                    </tr>
                    </thead>
                    <tbody>
                    {loop $list $index $item}
                    <tr>
                        <td>{$item['id']}</td>
                        <td>
                            <img src="{php echo tomedia($item['avatar']);}" style="width: 28px;height: 28px;padding: 1px;">
                            <br>
                            {$item['nickname']}
                        </td>
                        <td>{$item['username']}<br/>{$item['mobile']}</td>
                        <td>
                            {$item['gift_name']}
                        </td>
                        <td>
                            {$item['gift_price']}
                        </td>
                        <td>
                            {if $item['classify']=='tuan_gift'}
                              <span class="label label-success">成团礼</span>
                            {elseif $item['classify']=='invite_gift'}
                              <span class="label label-warning">邀请下单</span>
                            {elseif $item['classify']=='help_gift'}
                              <span class="label label-info">邀请助力</span>
                            {/if}
                        </td>
                        <td>
                            {$item['classify_info']}
                        </td>
                        <td >
                            {$item['workername']}<br>{$item['teamname']}<br>{php echo mb_substr($item['companyname'],0,6,'utf-8');}
                        </td>
                        <td>
                            {if $item['status']==1}
                             <span class="label label-warning">待核销</span>
                            {elseif $item['status']==2}
                                <span class="label label-success">已核销</span>
                                <br>
                                <span style="font-size: 10px;max-width: 100px;">
                                    {php echo substr($item['exchange_at'],0,10);}<br>
                                    {php echo substr($item['exchange_at'],10);}
                                </span>
                            {/if}
                        </td>

                        <td style="font-size: 10px;max-width: 100px;">
                            {php echo substr($item['created_at'],0,10);}<br>
                            {php echo substr($item['created_at'],10);}
                        </td>
                    </tr>
                    {/loop}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
{$pager}
<script type="text/javascript">
    var page = 0;
    var res = 'success';
    function jump(){
        layer.msg('正在准备下载');
    }
    function validation(){
        layer.alert('确认校验吗？',
            function (val, index) {
                var index = layer.load(2);
                gift_record_delete();
                setInterval(() => {
                    page++;
                    console.log(page,res)
                    if(res=='success'){
                        validation_ajax(page);
                    }else{
                        clearInterval();
                        layer.close(index);
                        layer.msg('效验成功');
                        window.location.reload();
                    }
                }, 2000);
            }
        )
    }
    function validation_ajax(page){
        $.ajax({
            url: "{php echo createWebUrlPlugin('gift.record.validation',array('themeid'=>$themeid));}",
            dataType: 'json',
            method: 'post',
            data: {
                page:page
            },
            success: function (e) {
                console.log(e.msg)
                res = e.msg;
            }
        })
    }
    function gift_record_delete(){
        $.ajax({
            url: "{php echo createWebUrlPlugin('gift.record.gift_record_delete',array('themeid'=>$themeid));}",
            dataType: 'json',
            method: 'post',
            data: {
                page:page
            },
            success: function (e) {
            }
        })
    }
</script>
